package com.yun.control;


import com.yun.entity.Dorm;
import com.yun.entity.dto.UpdateDormByRoomNoDto;
import com.yun.service.DormService;
import com.yun.util.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyj
 * @since 2021-09-07
 */
@RestController
@RequestMapping("/dorm")
public class DormController {
    @Autowired
    private DormService dormService;

    @ApiOperation ("获取所有宿舍信息")
    @GetMapping("/allDorm")
    public CommonResult getAllDorm(){
        List<Dorm> allDorm = dormService.getAllDorm ();
        if (allDorm.isEmpty ()){
            return CommonResult.failed ("暂无信息");
        }
        return CommonResult.success (allDorm);
    }

    @ApiOperation ("更新宿舍信息，根据房间号")
    @PutMapping("/updateDormByRoomNo")
    public CommonResult updateDormByRoomNo(UpdateDormByRoomNoDto updateDormByRoomNoDto){
        return dormService.updateDorm (updateDormByRoomNoDto);
    }

    @ApiOperation ("新增一条宿舍信息")
    @PostMapping
    public CommonResult insertDorm(Dorm dorm){
        return dormService.insertDorm (dorm);
    }

    @ApiOperation ("删除宿舍信息通过房间号")
    @DeleteMapping
    public CommonResult deleteDormByRoomNo(String roomNo){
        return dormService.deleteDormByRoomNo (roomNo);
    }




}

